<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');
$action=checkstr($_GET['action']);
if($action=="fahuo"){
  $id=checkstr($_GET['id'])."0";
  $sql="select * from ld_give_help where id in (".$id.")";

  $db->query($sql);
  $list=$db->rs;
  if($list){
    foreach ($list as $key => $v) {
      if($v['status']==2){
        continue;
      }
      $sqll="update  ld_give_help set is_fa=1 where id=".$v['id'];
      $db->query($sqll,4);
    }
  }
  show_automsg('发货成功！',YMCURL.'dzorders');
}
if ($action=="del"){
}

?>
<link rel="stylesheet" type="text/css" href="../css/pintuer.css">
<link rel="stylesheet" type="text/css" href="../css/admin.css">
<link rel="stylesheet" type="text/css" href="../css/manage.css">

<script language="javascript" type="text/javascript" src="../my97datepicker/WdatePicker.js"></script>
<script>

//批量发货
function piliang(){
  var obj=document.getElementsByName('checkbox'); //选择所有name="'test'"的对象，返回数组
  //取到对象数组后，我们来循环检测它是不是被选中
  var s='';

  for(var i=0; i<obj.length; i++){
  if(obj[i].checked) s+=obj[i].value+','; //如果选中，将value添加到变量s中
  }
  //那么现在来检测s的值就知道选中的复选框的值了
  //alert('sendgoods_pl.php?action=fahuo&id='+s);
  location.href='main.php?lsaction=dzorders'+'&action=fahuo&id='+s;
}

</script>
<div class="righttop">
  <span class="icon-home"></span> 首页 <span class="gray">/</span> 订单管理
</div>
<div class="panelbox">
    <div class="panel admin-panel">
        <div class="panel-head">
          <strong><span class="icon-edit"></span>
            订单列表
          </strong>
        </div>
        <div class="padding border-bottom" style="height: auto;overflow: hidden;">
          <ul class="search" >
            <li>
              <span class="button border-green colorgreen" >
                <span class="icon-rocket"></span>
                <a href="javascript:;" onClick="piliang()">批量发货</a>
              </span>
              <span class="button border-yellow coloryellow" style="display:none">
                <span class="icon-print"></span>
                <a href="javascript:;" onClick="prints()">批量打印</a>
              </span>
              <span class="button border-red colorred" >
                <span class="icon-share"></span>
                <a href="../down.php?&time1=<?php echo $_GET['time1'];?>&time2=<?php echo $_GET['time1'];?>&static=<?php echo $_GET['static'];?>&username=<?php echo $_GET['username']?>">导出Excel</a>
              </span>
              <span class="button border-red colorred" style="display:none">
                <span class="icon-share"></span>
                <a href="../excel/99.php?did=<?php echo $_SESSION["glo_admindepart"];?>&wuliu=<?php echo $wuliu;?>&state=<?php echo $state;?>&username=<?php echo $username;?>&time1=<?php echo $time1;?>&time2=<?php echo $time2;?>&action=<?php echo $action;?>&orderid=<?php echo $orderid;?>&static=<?php echo $static;?>&storerank=<?php echo $storerank;?>">导出汇总表</a>
              </span>
            </li>
          </ul>
          <div style="margin-top: 10px;">
            <form name="form2" method="get" action="<?php echo geturl()?>">
            <input type="hidden" name="lsaction" value="dzorders">
            <input type="hidden" name="act" value="query">
              <label class="searchlabel">起</label>
              <input name="time1" value="<?php echo $time1;?>" type="text" id="time1" class="input sehinput" onFocus="new WdatePicker(this,null,false,'whyGreen')">
              <label class="searchlabel">止</label>
              <input name="time2" type="text" value="<?php echo $time2;?>" id="time2" class="input sehinput" onFocus="new WdatePicker(this,null,false,'whyGreen')">
              <label class="searchlabel">用户名</label>
              <input name="username" type="text" id="username" value="<?php echo $username;?>" class="input sehinput">
              <label class="searchlabel">订单编号</label>
              <input name="orderid" type="text" id="orderid" value="<?php echo $orderid;?>" class="input sehinput">
              <div style="height: 10px;"></div>
                <?php
                // 判断是否为物控部
                  if($_SESSION["glo_admindepart"] != 6){
                ?>
                  <label class="searchlabel">状态</label>
                  <select name="static" class="select6">
                    <option value="" <?php if($_GET['static'] === ''){ echo 'selected';}?>>不限</option>
                    <option value='1' <?php if($_GET['static'] === '1'){ echo 'selected';}?>>未发货</option>
                    <option value='2' <?php if($_GET['static'] === '2'){ echo 'selected';}?>>已发货</option>
                  </select>
                <?php
                  }
                ?>
                <button class="button bg-main" type="submit"  id="but" value="" name="but"><sapn class="icon-check-square-o"></sapn> 查询</button>
                <INPUT class=button_text onMouseDown="this.className='button_onmousedown'" onMouseOver="this.className='button_onmouseover'" onMouseOut="this.className='button_onMouseOut'" type=reset  id="reset" value="重置" name="reset">
            </form>
          </div>
        </div>
        <div class="body-content" style="padding:0px;">
          <!-- 订单表格 -->
          <table class="table table-hover text-center">
              <tr>
                <th><input type="checkbox" name="checkboxs" id="alls" value='ss'/></th>

                <!-- 处理全选与全不选 -->
                <script type="text/javascript">
                  $("#alls").click(function(){
                    var aa = $(this).attr('checked');
                    if(!aa){
                      $('input[pro="pro"]').attr('checked', false);
                    }else{
                      $('input[pro="pro"]').attr('checked', true);
                    }
                  });
                </script>
                <th >订单编号</th>
                <th>用户名</th>
                <th>查看详情</th>
                <th>收货人</th>
                <th>电话</th>
                <th>地址</th>
                <th>状态</th>
                <th>购买时间</th>
                <th>操作</th>
              </tr>
            <?php
              //会员搜索
              $filter="";
              $action=checkstr($_GET['act']);
              if($action=="query"){
                 $username=checkstr($_GET['username']);
                 $time1=$_GET['time1'];
                 $time2=$_GET['time2'];
                 $orderid=checkstr($_GET['orderid']);
                  $static=checkstr($_GET['static']);
                 if (trim($username)!="") $filter.=" and uname='".trim($username)."'";
                 if (trim($time1)!="") $filter.=" and give_help_time>='".strtotime($time1)."'";
                 if (trim($time2)!="") $filter.=" and give_help_time<='".(strtotime($time2)+3600*24)."'";
                 if (trim($orderid)!=""){
                  $qno = substr($orderid,1,strlen($orderid)-1);
                  $queryno = dncorder($qno);
                    $filter.=" and (give_help_no like '%".$queryno."%')";
                 } 
                if($static==1){
                   $filter.=" and is_fa=0";

                }
                 if($static==2){
                   $filter.="  and is_fa=1";
                }


              }

              //----------------
                $pagecount=15;
                $condition=" where xf_type=1";
                $psql="select count(0) from ld_give_help $condition $filter";
                // var_dump($psql);
                $db->query($psql,3);
                $pcount=$db->fval;
                $pagecount=$pagecount;   //每页条数
                $astr="&lsaction=dzorders";    //Url
                $pagearr=pagelist($pagecount,$pcount,$astr);
                $offset=$pagearr[1];
              $db->query("select *,ld_give_help.id as aid from ld_give_help left join ld_address on uid=adid $condition $filter order by give_help_time desc limit $offset,$pagecount");
              $list=$db->rs;
              // var_dump($rs);
              if ($list){
              foreach ($list as $key => $rs) {
                 if($rs['is_fa']==0){
                    $status='<font color="red">未发货</font>';
                 }else{
                   $status='已签收';
                 }
                $help_no = get_help_no('give',$rs['uname'],$rs['give_help_no']);
              ?>
              <tr>
                <td><input type="checkbox" name="checkbox" pro="pro" value="<?php echo $rs['aid']?>" /></td>
                <td><?php echo $help_no;?></td>
                <td><?php echo $rs["uname"];?></td>
                
                <td>
                    
                <a style="color:blue;" href="javascript:;" onclick="showfellow('<?php echo $rs['aid']; ?>');">详细</a>
                </td>
               
                <td><?php echo $rs["addressname"]?></td>
                <td><?php echo $rs["phone"]?></td>
                <td><?php echo $rs["address"]?></td>
                <td><?php echo $status;?></td>
                <td><?php echo date("Y-m-d H:i",$rs["give_help_time"]);?></td>
                <td>
                     <a href="main.php?lsaction=orderview_1&id=<?php echo $rs["id"]?>">
                      查看
                    </a>|
                   
                    <?php 
                    if($rs['status']==1){?>
                   
                    |
                     <a href="main.php?lsaction=sendgoods&id=<?php echo $rs["id"]?>" >|&nbsp;发货</a>
                     <?php }?>
                </td>
              </tr>
              <?php
              }
              }
              else{
              ?>
              <tr>
                <td colspan="12"><div align="center"></div></td>
              </tr>
          <?php
          }
          ?>
            </table>
           </div>
          <!-- 订单表格结束 -->
          <?php if(($pcount/$pagecount)>1){?>
          <div class="pagediv"><?php echo $pagearr[0]?></div>
          <?php }?>
        </div>
    </div>
</div>
<script type="text/javascript" src="/theme/js/layer/layer.js"></script>
<script type="text/javascript">
layer.config({
  skin:'layer-ext-moon',
  extend:'skin/moon/style.css'
});
function closeAll(){
  layer.closeAll();
}
  function showfellow(id){
    $.ajax({
      type: "post",
      url: "/ajax.php?act=give_help_dzorders",
      dataType: "json",
      data:{"id":id},
      success: function(data){
        if (data.status) {
          var info=data.mes;
          for(var i=0;i<data.mes.length;i++){
            $("#helper_nick_name"+i).html("产品名："+info[i].productname);
            $("#helper_account"+i).html("数量："+info[i].num);

          }
        } else {
          alert(data.mes);
        }
      },
      error: function(){}
    });
    layer.open({
      type: 1,
      title: false,
      area: ['575px', '305px'],
      closeBtn: 0, //不显示关闭按钮
      shift: 2,
      shade:0,
      shadeClose: true, //开启遮罩关闭
      content: $('.layer_fellow')
    });
    return false;
  }
  function showdj(){
    layer.open({
      type: 1,
      title: ['领导奖（冻结）', 'font-size:14px;background-color:#b5c0c7;color:#fff;'],
      area: ['575px', '480px'],
      closeBtn: 1, //不显示关闭按钮
      shift: 2,
      shade:0,
      shadeClose: true, //开启遮罩关闭
      offset:['100px','10px'],
      scrollbar:true,
      content: $('.djglj')
    });
    return false;
  }
</script>
<div class="layer_fellow" style="display: none;">
<h4><span onclick="closeAll();" style="float:right;cursor:pointer;font-weight:normal;">关闭</span></h4>
  <?php for($i=0;$i<20;$i++){?>
  <div style="margin-top:20px;" id="helper_nick_name<?php echo $i?>"></div>
  <div id="helper_account<?php echo $i?>"></div>
  <?php }?>
</div>